﻿using System.Web;
using System.Web.Mvc;

namespace pbvs.Utilities.Assets
{
    public class AssetsHelper
    {
        public AssetsItemRegistrar Styles { get; private set; }
        public AssetsItemRegistrar Scripts { get; private set; }

        public AssetsHelper()
        {
            Styles = new AssetsItemRegistrar(AssetsItemRegistrar.StyleFormat);
            Scripts = new AssetsItemRegistrar(AssetsItemRegistrar.ScriptFormat);
        }

        public static AssetsHelper GetInstance(HtmlHelper htmlHelper)
        {
            const string instanceKey = "AssetsHelper";
            HttpContextBase context = htmlHelper.ViewContext.HttpContext;
            if (context == null)
            {
                return null;
            }

            AssetsHelper helper = (AssetsHelper) context.Items[instanceKey];
            if (helper == null)
            {
                context.Items.Add(instanceKey, helper = new AssetsHelper());
            }
            return helper;
        }
    }
}